/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ens.delegation.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ens.delegation.bo.Grade;
import org.ens.delegation.dao.IGradeDao;

/**
 *
 * @author amine
 */
public class GradeAction extends GenericAction {

    private Grade grade;
    private List listGradePag;
    private String[] columnsSort = {"", "descriptionFr", "descriptionAr"};
    private Map _jsonPaginator;
    private Map jsonResult;
    private Map jsonData;
    private String start;
    private String length;
    private String sort;
    private String sortdir;
    private String echo;
    private String strDescriptionFr;
    private String strDescriptionAr;
    private IGradeDao gradeDao;

    public GradeAction() {
    }

    public GradeAction(IGradeDao gradeDao) {
        this.gradeDao = gradeDao;
    }

    @Override
    public String execute() throws Exception {
        setGrade(null);
        setActionMessages(null);
        return SUCCESS;
    }

    @Override
    public String searchPaginator() {

        setJsonPaginator(new HashMap<String, Object>());

        setListGradePag(getGradeDao().findByFiltersWithFirstMaxResult(Integer.valueOf(getStart()), Integer.valueOf(getLength()), getColumnsSort()[Integer.valueOf(getSort())], getSortdir(), getStrDescriptionAr(), getStrDescriptionFr()));

        getJsonPaginator().put("sEcho", getEcho());

        Integer rowCount = getGradeDao().getRowCountByFilters(getStrDescriptionAr(), getStrDescriptionFr());

        getJsonPaginator().put("iTotalRecords", String.valueOf(rowCount));

        if (Integer.valueOf(getLength()).compareTo(rowCount) > 0) {
            getJsonPaginator().put("iTotalDisplayRecords", getLength());
        } else {
            getJsonPaginator().put("iTotalDisplayRecords", String.valueOf(rowCount));
        }

        String[][] aaData = new String[getListGradePag().size()][];
        for (int i = 0; i < getListGradePag().size(); i++) {
            Grade gr = (Grade) getListGradePag().get(i);
            String s[] = new String[4];
            s[0] = "<input type=\"checkbox\" name=" + gr.getId()
                    + "></input>";
            s[1] = gr.getDescriptionFr();
            s[2] = gr.getDescriptionAr();
            s[3] = "<a href=\"getGradesMod.go?ids=" + gr.getId()
                    + "\"><img src=\"./gfx/icon-edit.png\" alt=\"edit\" /></a>";
            aaData[i] = s;
        }

        getJsonPaginator().put("aaData", aaData);
        return SUCCESS;
    }

    @Override
    public String add() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String edit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String save() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String saveNew() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String delete() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * @return the _jsonPaginator
     */
    public Map getJsonPaginator() {
        return _jsonPaginator;
    }

    /**
     * @param jsonPaginator the _jsonPaginator to set
     */
    public void setJsonPaginator(Map jsonPaginator) {
        this._jsonPaginator = jsonPaginator;
    }

    /**
     * @return the jsonResult
     */
    public Map getJsonResult() {
        return jsonResult;
    }

    /**
     * @param jsonResult the jsonResult to set
     */
    public void setJsonResult(Map jsonResult) {
        this.jsonResult = jsonResult;
    }

    /**
     * @return the jsonData
     */
    public Map getJsonData() {
        return jsonData;
    }

    /**
     * @param jsonData the jsonData to set
     */
    public void setJsonData(Map jsonData) {
        this.jsonData = jsonData;
    }

    /**
     * @return the start
     */
    public String getStart() {
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(String start) {
        this.start = start;
    }

    /**
     * @return the length
     */
    public String getLength() {
        return length;
    }

    /**
     * @param length the length to set
     */
    public void setLength(String length) {
        this.length = length;
    }

    /**
     * @return the sort
     */
    public String getSort() {
        return sort;
    }

    /**
     * @param sort the sort to set
     */
    public void setSort(String sort) {
        this.sort = sort;
    }

    /**
     * @return the sortdir
     */
    public String getSortdir() {
        return sortdir;
    }

    /**
     * @param sortdir the sortdir to set
     */
    public void setSortdir(String sortdir) {
        this.sortdir = sortdir;
    }

    /**
     * @return the echo
     */
    public String getEcho() {
        return echo;
    }

    /**
     * @param echo the echo to set
     */
    public void setEcho(String echo) {
        this.echo = echo;
    }

    /**
     * @return the columnsSort
     */
    public String[] getColumnsSort() {
        return columnsSort;
    }

    /**
     * @param columnsSort the columnsSort to set
     */
    public void setColumnsSort(String[] columnsSort) {
        this.columnsSort = columnsSort;
    }

    /**
     * @return the grade
     */
    public Grade getGrade() {
        return grade;
    }

    /**
     * @param grade the grade to set
     */
    public void setGrade(Grade grade) {
        this.grade = grade;
    }

    /**
     * @return the listGradePag
     */
    public List getListGradePag() {
        return listGradePag;
    }

    /**
     * @param listGradePag the listGradePag to set
     */
    public void setListGradePag(List listGradePag) {
        this.listGradePag = listGradePag;
    }

    /**
     * @return the strDescriptionFr
     */
    public String getStrDescriptionFr() {
        return strDescriptionFr;
    }

    /**
     * @param strDescriptionFr the strDescriptionFr to set
     */
    public void setStrDescriptionFr(String strDescriptionFr) {
        this.strDescriptionFr = strDescriptionFr;
    }

    /**
     * @return the strDescriptionAr
     */
    public String getStrDescriptionAr() {
        return strDescriptionAr;
    }

    /**
     * @param strDescriptionAr the strDescriptionAr to set
     */
    public void setStrDescriptionAr(String strDescriptionAr) {
        this.strDescriptionAr = strDescriptionAr;
    }

    /**
     * @return the gradeDao
     */
    public IGradeDao getGradeDao() {
        return gradeDao;
    }

    /**
     * @param gradeDao the gradeDao to set
     */
    public void setGradeDao(IGradeDao gradeDao) {
        this.gradeDao = gradeDao;
    }
}
